// banner swapping
// "i'm gonna pack up my pencils and go home" - dlyons 
// $Id: livebanner.js,v 1.6 2004/02/01 23:48:19 awilli07 Exp $ 

function Arr() {
    var i;
    for(i = 0; i < Arr.arguments.length; i++)
        this[i] = Arr.arguments[i];
    this.length = i;
}

function Livebanner() {
    var args = Livebanner.arguments;
    this.src = args[0];
    this.href = args[1];
    this.alt = args[2];
    this.title = args[3];
    this.onclick = args[4];
}

function livebanner_init(name, docobj, count) {
    // find document objects
    for(var i = 0; i < count; i++) {
	docobj[i] = new Array;
        docobj[i].img = eval("document.img_" + name + i);
        docobj[i].anc = utility_findanchor("a_" + name + i);
    }
}

function livebanner_display(promos,docobj,current,state,prob,delay) {
    if(!state.lock) {
        // not loading an image, increment counter
	state.counter = (state.counter || 0) + 1000;
	if(state.counter >= delay) {
	    livebanner_swap(promos, docobj, current, state, prob);
            state.counter = 0;
        }
	else return;
    }
    if(!(state.img && state.img.complete))
	return; // still loading
	
    var i = state.i;
    var j = state.j;
    var doco  = docobj[i];
    var prom = promos[j];

    current[i] = j;
    doco.img.src = state.img.src;
    doco.img.alt = state.img.alt;
    if(doco.anc != null) {
	doco.anc.href = prom.href;
	doco.anc.onclick = prom.onclick;
	doco.anc.title = prom.title;
    }
    state.lock = 0;  // image loaded & displayed
}

function livebanner_swap(promos, docobj, current, state, prob) {
    if(state.lock) return;
    state.lock = 1;  // loading an image
    var select = utility_selectimg(promos.length, current, prob);
    var i = select.targ;
    var j = select.num;
    if(j < 0) {  // error selecting image
        state.lock = 0;
        return;
    }
    // load image before displaying
    state.img = new Image();
    state.img.src = promos[j].src;
    state.img.alt = promos[j].alt;
    state.href = promos[j].href;
    state.i = i;
    state.j = j;
}
